# -*-coding:utf-8-*-
import pandas as pd

pd.set_option('display.unicode.east_asian_width', True)
df: pd.DataFrame = pd.read_excel(r'..\book.xlsx', index_col=0)

"""
at：用行名和列名抽取单个数据
iat：用行号和列号抽取单个数据
loc：用行名和列名抽取区域数据，返回区间[start, stop]。如：df.loc['index1':'index5', 'column1':'column5']
iloc：用行号和列号抽取区域数据，参数是整型，返回区间[start, stop)。如：df.iloc[1:5, 1:5]
"""
# 抽取单个数据
a1 = df.loc['B01', '销量']
a2 = df.at['B01', '销量']
a3 = df.iat[0, 0]

# 抽取一行数据，返回series
s1 = df.loc['B01']
s2 = df.iloc[0]
# 抽取多行数据，返回dataframe
d1 = df.loc[['B01', 'B02']]
d2 = df.loc['B01':'B16']
d3 = df.iloc[[0, 1]]
d4 = df.iloc[0:2]

# 抽取一列数据，返回series
s3 = df['销量']
s4 = df.iloc[:, 3]
s5 = df.loc[:, '销量']
# 抽取多列数据，返回dataframe
d5 = df[['销量', '单价']]
d6 = df.loc[:, ['销量', '单价']]
d7 = df.iloc[:, 0:1]

# 抽取指定行列数据，返回dataframe
s6 = df.iloc[0:2, 0:2]
s7 = df.iloc[[0, 1], [0, 1]]

# 按条件抽取行数据
d8 = df[(df['销量'] > 500) & (df['单价'] > 70)]
d9 = df.loc[(df['销量'] > 500) & (df['单价'] > 70)]
